﻿using System.Collections.Generic;
using System.Data;
using System.Linq;

namespace Dqaqs.ProfileTableAlgorithm.Helpers
{
	internal static class TableHelper
	{
		internal static DataTable ReordrColumns(DataTable table, IEnumerable<string> orderedCols)
		{
			var rv = new DataTable(table.TableName);
			rv.Columns.AddRange(orderedCols.Select(c => new DataColumn(table.Columns[c].ColumnName, table.Columns[c].DataType)).ToArray());
			foreach (var drow in table.Rows.Cast<DataRow>())
			{
				var row = drow;
				rv.Rows.Add(orderedCols.Select(c => row[c]).ToArray());
			}
			return rv;
		}
	}
}
